class Solution(object):
    def maxLengthBetweenEqualCharacters(self, s):
        d = {}
        max_len = -1
        for index, c in enumerate(s):
            if c not in d:
                d[c] = index
            else:
                max_len = max(max_len, index - d[c] - 1)
        return max_len